# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=flatbuffers
pkgver=2.0.6
pkgrel=0
pkgdesc="Memory Efficient Serialization Library"
url="https://google.github.io/flatbuffers/"
# blocked by bus error in tests
arch="all !armhf"
license="Apache-2.0"
makedepends="cmake samurai"
subpackages="$pkgname-dev"
source="flatbuffers-$pkgver.tar.gz::https://github.com/google/flatbuffers/archive/v$pkgver.tar.gz
	disable-Werror.patch
	fix-version.patch
	"

# Bus error in armv7 as well but it has downstream users
case "$CARCH" in
	armv7) options="!check"
esac

# secfixes:
#   0:
#     - CVE-2020-35864

prepare() {
	default_prepare

	# flattests fails if out-of-source build directory is used
	# https://github.com/google/flatbuffers/issues/7282#issuecomment-1163114000
	sed -r -i 's@//((include|monster)_test)@//../../tests/\1@g' tests/test.cpp
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DFLATBUFFERS_BUILD_SHAREDLIB=ON \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm755 "$builddir"/build/flatc \
		"$pkgdir"/usr/bin/flatc
}

sha512sums="
be631f34064c28d81876bf137c796e9736623cf2cc4f2a05dd45372e7195729c99fad1fa795f8ce71a408756a842edbdc0c3bc714a7cf63203a1de8681d86fb6  flatbuffers-2.0.6.tar.gz
c80587472f2d498681410f283f8b40a65f8c73711b8086b46a3f4d5b419cfa65331c66d4d5d13a42b449eec673ea283c8170d5bed2b9a15e8b71b4f9a66e18d5  disable-Werror.patch
e6a13b86211ac9034402c0e5801f31362ee50ba0922e1c6bdedc8f0347490ce0cea230259d7952ced16e5ebe0682c9db7961811bceac4c84627f91bc5dd2401a  fix-version.patch
"
